#include "pagemannualtest.h"
#include "ui_pagemannualtest.h"

PageMannualTest::PageMannualTest(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::PageMannualTest)
{
    ui->setupUi(this);
    setAutoFillBackground(true);  //设置自动填充
    QPalette palette = BKGCLR;
    setPalette(palette);

    m_lBrkManSelfTestList.append(ui->BrkManSelfTest_1);
    m_lBrkManSelfTestList.append(ui->BrkManSelfTest_4);

    setPageActive(false);

    ui->BrkNotSatisfy_1->hide();
    ui->BrkNotSatisfy_6->hide();
}

PageMannualTest::~PageMannualTest()
{
    delete ui;
}

void PageMannualTest::on_Btn_Return_clicked()
{
    emit returnToMaintMenu();
}

void PageMannualTest::setBrkManSelfTestStat(uint8_t index, uint8_t stat)
{
    if(index >= m_lBrkManSelfTestList.length())
        return;
    switch (stat) {
    case 0:
        m_lBrkManSelfTestList[index]->setStyleSheet("background-color: rgb(147,147,147);border:1px solid rgb(64,64,64);color:white;font:15pt 'arial';");
        m_lBrkManSelfTestList[index]->setText("?");
        break;
    case 1:
        m_lBrkManSelfTestList[index]->setStyleSheet(LabelGreenStyle);
        m_lBrkManSelfTestList[index]->setText("进行中");
        break;
    case 2:
        m_lBrkManSelfTestList[index]->setStyleSheet(LabelRedStyle);
        m_lBrkManSelfTestList[index]->setText("故障");
        break;
    case 3:
        m_lBrkManSelfTestList[index]->setStyleSheet(LabelGreenStyle);
        m_lBrkManSelfTestList[index]->setText("成功");
        break;
    default:
        m_lBrkManSelfTestList[index]->setStyleSheet("background-color: rgb(147,147,147);border:1px solid rgb(64,64,64);color:white;font:15pt 'arial';");
        m_lBrkManSelfTestList[index]->setText("?");
        break;
    }
}

void PageMannualTest::on_Btn_BrkTest_clicked()
{
    emit signal_BrkManTest(true);
    ui->Btn_BrkTest->setEnabled(false);
    QTimer::singleShot(5000,this,[=](){
        emit signal_BrkManTest(false);
        ui->Btn_BrkTest->setEnabled(true);
    });
}

void PageMannualTest::setPageActive(bool xActive)
{
    ui->Btn_BrkTest->setEnabled(xActive);
}
